$(function() {
	
	jQuery.validator.addMethod("urlRegex", function(value, element) {   
		return this.optional(element) || /^((admin)|(oauth)){1}.+(\.action)$/.test(value);   
	}, "请输入正确的权限标签");

	$("#add_url_form").validate({
		errorPlacement:function(error,element) {  
			element.parent().find(".verror").html(error);
		},
		rules:{
			"roleUrl.name":{
				required:true,
				remote: {
					url: base + "oauth/roleUrl/checkUrlName.action", 
					type: "POST", 
					data: {"roleUrl.id": ($("#roleUrl.id").val()), "roleUrl.name": ($("#roleUrl.name").val())}
				}
			},
			"roleUrl.url":{
				required: true,
				urlRegex: true
			}
		},
		messages:{
			"roleUrl.name": {
				required: "请输入链接名称", 
				remote: "该名称已被使用"
			},
			"roleUrl.url": {
				required: "请输入链接地址",
				urlRegex: "请输入正确的链接地址",
			}
		}
	});
});